<template>
  <div o-Container>
    <o-list v-bind:source="list.contract"
            v-bind="{created:create,exported:output,modified:modify,searched:search}"/>
    <o-dialog v-bind:source="panel" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.contract" v-bind="{saved:save,backed:back}"></o-item>
      </template>
    </o-dialog>
  </div>
</template>

<script>
  export default {
    name: "mms_cus_contract_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          contract: {
            data: {
              id: 631,
              cellData: [
                {name: "ProjectID", width: 200, searchKey: "="},	// 所属项目
                {name: "ProprietorID", width: 300, searchKey: "=",link: [{binding: "ProjectID", mapping: "ProjectID"}]},	// 所属业主
                {name: "Code", width: 200, searchKey: "LIKE"},	// 合同代码
                // {name: "FullName", width: 200},	// 合同号全名
                {name: "StartTime", width: 100, searchKey: "BETWEEN"},	// 起租日期
                {name: "EndTime", width: 100, searchKey: "BETWEEN"},	// 退租日期
                {name: "ElectricityPower"},	// 合同约定功率
                {name: "Signatory", width: 100, searchKey: "LIKE"},	// 招商人员
                {name: "SigningDate"},	// 招商日期
                {name: "Amount"},	// 合同金额
                {name: "State"},	// 业主状态
                {name: "CreateTime", width: 170},	// 注册日期
              ],
            }
          },
        },
        item: {
          contract: {
            data: {
              id: 629,
              cellData: [
                {name: "ProjectID"},	// 所属项目
                {name: "ProprietorID",link: [{binding: "ProjectID", mapping: "ProjectID"}]},	// 所属业主
                {name: "Code"},	// 合同代码
                // {name: "FullName", width: 200},	// 合同号全名
                {name: "StartTime"},	// 起租日期
                {name: "EndTime"},	// 退租日期
                {name: "ElectricityPower"},	// 合同约定功率
                {name: "Signatory"},	// 招商人员
                {name: "SigningDate"},	// 招商日期
                {name: "Amount"},	// 合同金额
                {name: "State"},	// 业主状态
                {name: "CreateTime"},	// 上传日期
              ]
            },
          },
        },
        panel: {
          visible: false,
        },
      }
    },
    created: function () {
      this.init();
    },
    methods: {
      init: function () {
        let url = this.octopus.vue.$route.path;
        // MMS
        if (url.indexOf("MMS/Project/contract/List") > -1) {
          // this.octopus.tools.parseCell(this.item.contract.data, "ProprietorID").link = null;
          // this.octopus.tools.parseCell(this.item.contract.data, "ElectricityPriceID").link = null;
        }
        // MDM
        else {
          // alert(this.octopus.passport.authorization.company);
          // this.octopus.tools.parseCell(this.list.contract.data, "CompanyID").show = false;
          // this.octopus.tools.parseCell(this.list.contract.data, "CompanyID").searchKey = null;
          // this.octopus.tools.parseCell(this.list.contract.data, "CompanyID").filterValue = this.octopus.passport.authorization.company;
          // this.octopus.tools.parseCell(this.list.contract.data, "ProjectID").show = false;
          // this.octopus.tools.parseCell(this.list.contract.data, "ProjectID").filterValue = this.octopus.passport.project;
          // // this.octopus.tools.parseCell(this.list.contract.data, "ProjectID").link = null;
          // this.octopus.tools.parseCell(this.list.contract.data, "AreaID").link = [{
          //   mapping: "ProjectID",
          //   value: this.octopus.passport.project
          // }];

          // this.octopus.tools.parseCell(this.list.contract.data, "BuildingID").link = [{
          //   mapping: "ProjectID",
          //   value: this.octopus.passport.project
          // }];
        }
      },
      create: function () {
        this.item.contract.data.value = null;
        this.item.contract.control.load();//新增没有数据加载
        this.panel.visible = true;
      },
      output: function (data) {
        this.octopus.tips.success("下载完成。");
        // 导出以后，回调这里给客户端操作。
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
      },
      search: function (cell) {
      },
      modify: function (row) {//编辑
        this.item.contract.data.value = row.ID;
        this.item.contract.control.load();//编辑根据行id请求数据；然后加载
        this.panel.visible = true;
      },
      del: function (row) {
        alert("del key: " + JSON.stringify(row));
      },
      save: function (data) {
        this.octopus.tips.success(data);
        // 刷新list
        this.list.contract.control.load();
        this.back();
      },
      back: function () {
        this.panel.visible = false;
      }
    },
    props: ["oData"]
  }
</script>
